core: Fix handling of hardlinks for tar commits
authorColin Walters <walters@verbum.org>
Sun, 4 Dec 2011 19:38:30 +0000 (14:38 -0500)
committerColin Walters <walters@verbum.org>
Sun, 4 Dec 2011 19:38:30 +0000 (14:38 -0500)
We were creating files with the wrong name.  Add a test.

src/libostree/ostree-repo.c
tests/t0006-libarchive.sh

index 6d541d391faa8edf74297f505681721b773acad9..de8230ffe33f2321924dbc7ac59b55db2172b0fe 100644 (file)
@@ -1730,10 +1730,10 @@ import_libarchive (OstreeRepo           *self,
           if (!file_tree_walk (root, hardlink_split_path, 0, &hardlink_parent, error))
             goto out;
 
-          g_assert (parent);
 
           hardlink_basename = hardlink_split_path->pdata[hardlink_split_path->len - 1];
 
+          g_assert (parent);
           hardlink_source_checksum = g_hash_table_lookup (hardlink_parent->file_checksums, hardlink_basename);
           if (!hardlink_source_checksum)
             {
@@ -1743,8 +1743,15 @@ import_libarchive (OstreeRepo           *self,
               goto out;
             }
 
+          if (g_hash_table_lookup (parent->subdirs, basename))
+            {
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "Directory exists: %s", hardlink);
+              goto out;
+            }
+
           g_hash_table_replace (parent->file_checksums,
-                                g_strdup (hardlink_basename),
+                                g_strdup (basename),
                                 g_strdup (hardlink_source_checksum));
           continue;
         }
index 6f1a9e1d5bbc2ead0a09ed887f33b01afb6bea5d..76bcd88cb4a937bf6ba7afc1fb934275261a00ed 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..1"
+echo "1..4"
 
 . libtest.sh
 
@@ -39,5 +39,36 @@ echo not > subdir/2/notempty
 
 tar -c -z -f ../foo.tar.gz .
 cd ..
-$OSTREE commit -s "from tar" -b test2 --tar foo.tar.gz
+$OSTREE commit -s "from tar" -b test-tar --tar foo.tar.gz
 echo "ok tar commit"
+
+cd ${test_tmpdir}
+$OSTREE checkout test-tar test-tar-checkout
+cd test-tar-checkout
+assert_file_has_content hi hi
+assert_file_has_content hello hi
+assert_file_has_content subdir/more contents
+assert_has_file subdir/1/empty
+assert_has_file subdir/2/empty
+cd ${test_tmpdir}
+rm -rf test-tar-checkout
+echo "ok tar contents"
+
+cd ${test_tmpdir}
+mkdir hardlinktest
+cd hardlinktest
+echo other > otherfile
+echo foo1 > foo
+ln foo bar
+tar czf ${test_tmpdir}/hardlinktest.tar.gz .
+cd ${test_tmpdir}
+$OSTREE commit -s 'hardlinks' -b test-hardlinks --tar hardlinktest.tar.gz
+rm -rf hardlinktest
+echo "ok hardlink commit"
+
+cd ${test_tmpdir}
+$OSTREE checkout test-hardlinks test-hardlinks-checkout
+cd test-hardlinks-checkout
+assert_file_has_content foo foo1
+assert_file_has_content bar foo1
+echo "ok hardlink contents"